package util;

import enmu.ItemType;
import model.Item;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

public class ItemUtil {

    /**
     * 获取所有商品列表
     *
     * @return 商品列表
     */
    public static List<Item> getAllItems() {
        List<Item> allItems = new ArrayList<>();
        allItems.add(hamburger());
        allItems.add(fries());
        allItems.add(chickenWrap());
        allItems.add(icedCoffee());
        allItems.add(cola());
        allItems.add(orangeJuice());
        allItems.add(iceCream());
        allItems.add(cake());
        return allItems;
    }

    /**
     * 获取单个商品的信息
     *
     * @param itemId 商品id
     * @return 商品信息
     */
    public static Item getItemInfo(String itemId) {
        List<Item> allItems = getAllItems();
        Optional<Item> find = allItems.stream().filter(item -> item.getId().equals(itemId)).findFirst();
        return find.orElse(null);
    }

    // 主食类
    public static Item hamburger() {
        return new Item("H001", "汉堡", 15.0, ItemType.MAIN);
    }

    public static Item fries() {
        return new Item("F002", "薯条", 15.0, ItemType.MAIN);
    }

    public static Item chickenWrap() {
        return new Item("W003", "鸡肉卷", 12.0, ItemType.MAIN);
    }

    // 饮料类
    public static Item icedCoffee() {
        return new Item("C004", "冰咖啡", 10.0, ItemType.DRINK);
    }

    public static Item cola() {
        return new Item("C005", "可乐", 8.0, ItemType.DRINK);
    }

    public static Item orangeJuice() {
        return new Item("J006", "橙汁", 9.0, ItemType.DRINK);
    }

    // 甜品类
    public static Item iceCream() {
        return new Item("D007", "冰淇淋", 6.0, ItemType.DESSERT);
    }

    public static Item cake() {
        return new Item("D008", "蛋糕", 12.0, ItemType.DESSERT);
    }

}
